package servlet.image;

import bean.Result;
import com.google.gson.Gson;
import dao.ProductImage;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(name = "QueryImageByProidServlet", value = "/QueryImageByProidServlet.s")
public class QueryImageByProidServlet extends HttpServlet {
    private ProductImage dao = new ProductImage();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        final String proid = request.getParameter("proid");
        final Map<String, Object> image = dao.GetMainImage(proid);
        final List<Map<String, Object>> images = dao.GetOtherImage(proid);
        final List<Map<String, Object>> allImage = dao.GetAllImages(proid);
        Map<String,Object> result = new HashMap<>();
        result.put("mainImage",image);
        result.put("images",images);
        result.put("allImage",allImage);
        final String json = new Gson().toJson(result);
        response.getWriter().append(json);
    }
}
